#include "header.h"
#include "critical.h"
#include "extern.h"

int mutex_create_all (void)
{

int res, i;

	for (i=0; i < ServerConf.MaxClients; i++){
		res = MUTEX_INIT(sockets[i].mutex);
				if (res != 0){
					fprintf (stderr, "mutex init error\n");
					return -1;
				}
	}

	res = MUTEX_INIT(ThreadsCounter_mutex);
		if (res != 0){
			fprintf (stderr, "mutex init error\n");
			return -1;
		}

	res = MUTEX_INIT(auth_mutex);
		if (res != 0){
			fprintf (stderr, "mutex init error\n");
			return -1;
		}

	res = MUTEX_INIT(clientinsert_mutex);
		if (res != 0){
			fprintf (stderr, "mutex init error\n");
			return -1;
		}

 return 0;
}

void mutex_del_all (void)
{
int i;

	for (i=0; i < ServerConf.MaxClients; i++)
		pthread_mutex_destroy (&sockets[i].mutex);

	pthread_mutex_destroy (&ThreadsCounter_mutex);
	pthread_mutex_destroy (&auth_mutex);
	pthread_mutex_destroy (&clientinsert_mutex);
}



